package cn.yours.elfinder.core.impl.minio;

import io.minio.MinioClient;
import io.minio.Result;
import io.minio.errors.*;
import io.minio.messages.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * Helper class for NIO file system operations.
 *
 * @author Van
 */
public final class MinioService {

    private static final Logger logger = LoggerFactory.getLogger(MinioService.class);

    private MinioClient minioClient;


    public MinioService(String endpoint, String accessKeyId, String accessKeySecret) {
        try {
            this.minioClient = new MinioClient(endpoint, accessKeyId, accessKeySecret);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean isBucketExists(String bucketName) {
       try {
        return   minioClient.bucketExists(bucketName);
       }catch (Exception e){
           e.printStackTrace();
       }
       return false;
    }
    public Item getRootItem(String bucketName) {
        return null;
    }

    public boolean isFolder(String key) {
        return false;
    }


    public Item getOssObjectSummary(String bucketName, String ossKey) {
        try {
            Iterable<Result<Item>> results = minioClient.listObjects(bucketName, ossKey, true);
            Item item=null;
            for (Result<Item> result : results) {
                item= result.get();
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    public String fixOssFolderName(String path) {
        return null;
    }

    public void createFile(String bucketName, String path) {
        try {
//            minioClient.putObject(bucketName,path);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public List<Item> listChildren(String bucketName, String path) {
        return null;
    }

    public boolean hasChildFolder(String bucketName, String path) {
        return false;
    }

    public InputStream openInputStream(String bucketName, String path) {
        return null;
    }

    public void createFile(String bucketName, String path, byte[] bytes) {

    }

    public void createFile(String bucketName, String path, InputStream inputStream) {

    }

    public boolean isRoot(String key) {
        return false;
    }

    public void deleteFolder(String bucketName, String key) {

    }

    public void deleteFile(String bucketName, String key) {

    }

    public boolean exists(String bucketName, String key) {
        return false;
    }

    public String getMimeType(String bucketName, String key) {
        return null;
    }
}
